#!/usr/bin/env bash

set -eu

yum-builddep -y /src/rpm/SPECS/darling.spec
if [ -e "/src/rpm/SOURCES/darling.tar.gz" ]; then
  ln -s /src/rpm/SOURCES/darling.tar.gz /root/rpmbuild/SOURCES/
else
  # Preparing tarball
  tar --transform "s|^\./|./darling/|" -cf /root/rpmbuild/SOURCES/darling.tar.gz -C /src --exclude=.git --exclude SOURCES --exclude SRPMS --exclude RPMS .
fi
ln -s /src/rpm/SOURCES/dkms.conf /root/rpmbuild/SOURCES/

DARLING_COMMIT_DATE="$(cd /src; git describe --tags HEAD)"
export DARLING_COMMIT_DATE="${DARLING_COMMIT_DATE//-/}"

#spectool -g -R /src/rpm/SPECS/darling.spec
rpmbuild -ba /src/rpm/SPECS/darling.spec
